// test_api.js - 测试API功能
const axios = require('axios');

async function testAPI() {
    try {
        console.log("测试基本页面访问...");
        const homeResponse = await axios.get('http://localhost:3000/');
        console.log("✓ 主页访问成功:", homeResponse.status);
        
        console.log("\n测试RAG搜索接口...");
        const searchResponse = await axios.post('http://localhost:3000/api/rag/search', {
            query: "React Hooks",
            k: 2
        });
        console.log("✓ RAG搜索接口调用成功:", searchResponse.status);
        console.log("搜索结果数量:", searchResponse.data.length);
        console.log("第一个结果预览:", searchResponse.data[0]?.pageContent?.substring(0, 100) + "...");
        
    } catch (error) {
        if (error.response) {
            console.error("API调用失败:", error.response.status, error.response.statusText);
            console.error("响应数据:", error.response.data);
        } else {
            console.error("请求失败:", error.message);
        }
    }
}

testAPI();